package com.gitee.wsl.reflect.func.library

import com.gitee.wsl.reflect.func.Function

/**
 * A bundle of functions that can be called from a Quarkdown source.
 * @param name name of the library
 * @param functions functions the library makes available to call
 * @param onLoad optional action to run when the library is loaded in a context
 * @param hooks optional actions to run after each stage of a pipeline where this library is registered in has been completed
 */
data class Library(
    val name: String,
    val functions: Set<Function<*>>,
    val onLoad: (() -> Unit)? = null,
    //val hooks: PipelineHooks? = null,
) {
    /**
     * @return a copy of this library with the given pipeline hooks attached
     */
    //fun withHooks(hooks: PipelineHooks) = copy(hooks = hooks)
    companion object
}

/**
 * A compacter of a library project into a single [Library] object.
 * A library project must contain one class implementing this interface.
 */
interface LibraryExporter {
    /**
     * The library to export and hand to the pipeline.
     */
    val library: Library

    companion object {
        /**
         * Loads libraries from the given exporters.
         * @param exporters library exporters
         * @return set of exported libraries from the given exporters
         */
        fun exportAll(vararg exporters: LibraryExporter): Set<Library> = exporters.map { it.library }.toSet()
    }
}


